|
|
|
|
|
|
|
Answer to Day 19 Exercise |
|
|
|
|
|
|
|
|
To complete this assignment, you must first register a new ODBC data source on your workstation. To do this: |
|
|
|
|
|
|
|
|
1. Call up the ODBC Administrator from the Windows Control Panel. |
|
|
|
|
|
|
|
|
2. Press the Add button, and select Microsoft Access as the database driver. |
|
|
|
|
|
|
|
|
3. Set the DSN name to Exer19 and then press the Database button to select the target database (C:\TYSDBVB5\SOURCE\CHAP19\EXERCISE\EXER19.MDB). |
|
|
|
|
|
|
|
|
4. Select OK to save the new ODBC definition. |
|
|
|
|
|
|
|
|
Next you need to create a Visual Basic 5.0 Standard EXE project that is almost identical to the prjSQLTest project you built in this chapter. If you want, you can copy that project to a new directory and make the following changes: |
|
|
|
|
|
|
|
|
1. Copy the prjSQLTest project to a new directory. |
|
|
|
|
|
|
|
|
2. Load the prjSQLTest project. |
|
|
|
|
|
|
|
|
3. Modify the StartDB method to match the following code: |
|
|
|
|
|
|
|
|
Public Sub StartDB()
'
' handle chores of connecting and getting data
'
' create reference to ODBC object
Set objSQL = New objODBC
'
' populate properties
objSQL.DataSource = "Exer19" ' <<< modified line
objSQL.UserID = "admin"
objSQL.Password = ""
objSQL.SQL = "SELECT * FROM SampleTable" ' <<< modified line
objSQL.Table = "SampleTable" ' <<< modified line
objSQL.Key = "Name"
objSQL.ResultSetType = sqlStatic
objSQL.CursorDriver = sqlUseODBC
objSQL.LockType = sqlValues
'
' do real work
objSQL.Connect ' establish connection
objSQL.Refresh ' build dataset
objSQL.MoveFirst Me ' display first row
'
End Sub |
|
|
|
|
|
|
|
|
4. Modify the screen to contain three input boxes and three label controls. Set the label control captions to: Name, Address, and Phone. |
|
|
|
|
|
|
|
|
5. Save and run the project. |
|
|
|
|
|